package group.rober.jeki.admin.controller

import group.rober.jeki.entity.Tag
import group.rober.jeki.service.ArticleService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.servlet.ModelAndView

@Controller
@RequestMapping("/admin")
class AdminArticleController {
    @Autowired
    ArticleService articleService;

    @RequestMapping("/article-list")
    ModelAndView articleList() {
        Map<String,Object> vars = new HashMap<String,Object>();
        vars.put("articleList",articleService.getArticleList());
        return new ModelAndView("views/admin/article-list",vars);
    }
    @RequestMapping("/article/delete/{articleId}")
    ModelAndView deleteArticle(@PathVariable("articleId") String articleId) {
        articleService.deleteArticle(articleId);
        return new ModelAndView("redirect:/admin/article-list");
    }
    @RequestMapping("/article/stick/{articleId}")
    ModelAndView stickArticle(@PathVariable("articleId") String articleId) {
        articleService.stickArticle(articleId);
        return new ModelAndView("redirect:/admin/article-list");
    }
    @RequestMapping("/article/stick-cancel/{articleId}")
    ModelAndView stickCancelArticle(@PathVariable("articleId") String articleId) {
        articleService.cancelArticle(articleId);
        return new ModelAndView("redirect:/admin/article-list");
    }
}
